<template>
  <div class="user-info">
    <!-- 个人信息 -->
    <el-form ref="userForm" :model="userInfo" label-width="220px">
      <!--手机 -->

      <el-row class="inline-info">
        <el-col :span="12">
          <el-form-item label="手机">
            <el-input v-model="userInfo.mobile" />
          </el-form-item>
        </el-col>
      </el-row>
      <!-- 工号 入职时间 -->
      <el-row class="inline-info">
        <el-col :span="12">
          <el-form-item label="入职时间">
            <el-date-picker
              v-model="userInfo.timeOfEntry"
              type="date"
              class="inputW"
              value-format="yyyy-MM-dd"
            />
          </el-form-item>
        </el-col>
      </el-row>

      <!-- 员工照片 -->
      <el-form-item label="员工头像">
        <!-- 放置上传图片 -->
        <!-- <img :src="userInfo.staffPhoto"> -->
        <UploadImg v-model="userInfo.staffPhoto" />
      </el-form-item>

      <!-- 保存个人信息 -->
      <el-form-item>
        <el-button type="primary" @click="hSubmit">保存更新</el-button>
        <el-button @click="$router.back()">返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
// 用户个人信息
import { getUserDetailById } from '@/api/user.js'
import { saveUserDetailById } from '@/api/employees.js'
export default {
  data() {
    return {
      userId: this.$route.query.id,
      userInfo: {
        mobile: '',
        timeOfEntry: ''
      }

    }
  },
  created() {
    this.loadUserDetailById()
  },
  methods: {
    // 请求数据
    async loadUserDetailById() {
      try {
        const res = await getUserDetailById(this.$route.query.id)
        console.log('获取用户个人信息', res)
        this.userInfo = res.data // 保存数据
      } catch (err) {
        console.log(err)
        console.log('user-info页面错误提示', err)
      }
    },
    // 更新按钮
    async doEdit() {
      try {
        const res = await saveUserDetailById(this.userInfo)
        console.log('saveUserDetailById', res)
        this.$message.success('修改成功')
        //  回到列表页
        this.$router.back()
      } catch (err) {
        console.log('user-info页面错误提示', err)
      }
    },
    // 点击了更新按钮
    hSubmit() {
      // 兜底校验
      this.$refs.userForm.validate(valid => {
        // 高级简写
        valid && this.doEdit()
      })
    }
  }

}
</script>

<style scoped lang="scss">
  .user-info{
    padding-top:20px;
  }
</style>
